package com.example.demo.model;

import com.baidu.bas.annotation.Erupt;
import com.baidu.bas.annotation.EruptField;
import com.baidu.bas.annotation.sub_field.Edit;
import com.baidu.bas.annotation.sub_field.EditType;
import com.baidu.bas.annotation.sub_field.View;
import com.baidu.bas.annotation.sub_field.sub_edit.Search;
import com.baidu.bas.upms.model.EruptUser;
import com.baidu.bas.upms.model.base.HyperModel;
import com.example.demo.model.custom.AccountDataProxy;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.util.Date;

/**
 * @author liuzhenchuan@foxmail.com
 * @date 2020/12/28
 */
@Setter
@Getter
@Erupt(name = "账号",dataProxy = {AccountDataProxy.class},orderBy = "id desc")
@Table(name = "ma_channel_account")
@Entity
@TypeDef(name = "json", typeClass = JsonStringType.class)
@DynamicUpdate
public class Account extends HyperModel {

    @EruptField(
            views = @View(title = "账号名称"),
            edit = @Edit(title = "账号名称",type = EditType.INPUT)
    )
    private String name;

    @Type(type = "json")
    @Column(name = "config", columnDefinition = "json")
    @EruptField(
            views = @View(title = "账号配置"),
            edit = @Edit(title = "账号配置",type = EditType.HIDDEN)
    )
    private com.deepzero.mmma.channel.Account config;

    @EruptField(
            views = @View(title = "账号类型"),
            edit = @Edit(title = "账号类型",type = EditType.HIDDEN)
    )
    private String type;

    @EruptField(
            views = @View(title = "账号地址"),
            edit = @Edit(title = "账号地址",type = EditType.HIDDEN)
    )
    private String address;

    @ManyToOne
    @EruptField(
            views = {
                    @View(title = "ID", column = "id"),
                    @View(title = "渠道", column = "name")
            },
            edit = @Edit(title = "渠道", type = EditType.REFERENCE_TABLE, search = @Search)
    )
    private Channel channel;

    @EruptField(
            views = @View(title = "是否开启"),
            edit = @Edit(title = "是否开启",type = EditType.HIDDEN)
    )
    private Boolean enable = true;

    @EruptField(
            views = @View(title = "创建时间"),
            edit = @Edit(title = "创建时间",type = EditType.HIDDEN,readOnly = true)
    )
    private Date createTime;

    @ManyToOne(
            fetch = FetchType.EAGER
    )
    @EruptField(
            views = @View(title = "创建人", column = "name"),
            edit = @Edit(title = "创建人", type = EditType.REFERENCE_TABLE, search = @Search,readOnly = true)
    )
    private EruptUser createUser;

}
